package com.jeespring.shardingjdbc.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jeespring.shardingjdbc.entity.Order;
import com.jeespring.shardingjdbc.mapper.OrderMapper;
import com.jeespring.shardingjdbc.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OrderServiceImpl implements OrderService {

    @Autowired
    private OrderMapper orderMapper;

    @Override
    public List<Order> select(Order order) {
        Wrapper<Order> queryWapper = new QueryWrapper<>();
        return orderMapper.selectList(queryWapper);
    }

    @Override
    public IPage<Order> selectPage(Order order, int pageNumber, int pageSize) {
        IPage<Order> page = new Page<>();
        Wrapper<Order> queryWapper = new QueryWrapper<>();
        return orderMapper.selectPage(page, queryWapper);
    }

    @Override
    public List<Order> selectAll() {
        return orderMapper.selectAll();
    }

    @Override
    public int insert(Order order) {
        return orderMapper.insert(order);
    }

    @Override
    public int delete(Order order) {
        Wrapper<Order> wapper = new QueryWrapper<>();
        return orderMapper.delete(wapper);
    }

    @Override
    public int update(Order order) {
        UpdateWrapper<Order> wapper = new UpdateWrapper<>();
        wapper.eq("id", 3);
        return orderMapper.update(order, wapper);
    }
}
